﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>考试编辑</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Le styles -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
        body {
            padding-top: 60px;
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
    <link href="./css/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="css/datetimepicker.css" rel="stylesheet" type="text/css" />
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="//cdnjs.bootcss.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
    <![endif]-->
    <!-- Fav and touch icons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
    <link rel="shortcut icon" href="../assets/ico/favicon.png">
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container-fluid">
                <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a class="brand" href="#">学生成绩管理系统</a>
                <div class="nav-collapse collapse">
                    <p class="navbar-text pull-right">
                        Logged in as <a href="#" class="navbar-link">Username</a>
                    </p>
                    <ul class="nav" id="mainMenu">
                    </ul>
                </div>
                <!--/.nav-collapse -->
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div id="main-left" class="span3">
                <div class="well sidebar-nav bs-docs-sidebar">
                    <ul class="nav nav-list bs-docs-sidenav">
                        <li class="nav-header" id="sideTitle">考试编辑</li>
                        <li class="active"><a href="#singleAdd">添加考试</a></li>
                        <li><a href="#multiEdit">修改考试</a></li>
                        <li><a href="#finalEdit">期末成绩计算</a></li>
                    </ul>
                </div>
                <!--/.well -->
            </div>
            <!--/span-->
            <div id="main-right" class="span9">
                <section id="singleAdd">
                    <div class=" hero-unit">
                        <form class="form-horizontal">
                            <fieldset>
                                <div id="legend" class="">
                                    <legend class="">添加考试</legend>
                                </div>
                                <div class="control-group">
                                    <!-- Select Basic -->
                                    <label class="control-label">
                                        选择课程</label>
                                    <div class="controls">
                                        <select id="select-course" class="input-xlarge">
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <!-- Text input-->
                                    <label class="control-label" for="input01">
                                        考试名称</label>
                                    <div class="controls">
                                        <input id="exzamname" type="text" placeholder="考试名称" class="input-xlarge">
                                        <p class="help-block">
                                        </p>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <!-- Text input-->
                                    <label class="control-label" for="input01">
                                        考试时间</label>
                                    <div class="controls">
                                        <input id="starttime" type="text" placeholder="考试开始时间" class="input-small">到
                             <input id="endtime" type="text" placeholder="考试结束时间" class="input-small">
                                        <p class="help-block">
                                        </p>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <!-- Text input-->
                                    <label class="control-label" for="exzamplace">
                                        考试地点</label>
                                    <div class="controls">
                                        <input id="exzamplace" type="text" placeholder="placeholder" class="input-xlarge">
                                        <p class="help-block">
                                        </p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <!-- Select Basic -->
                                    <label class="control-label">
                                        考试类别</label>
                                    <div class="controls">
                                        <select id="select-exzamtype" class="input-large">
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <!-- Textarea -->
                                    <label class="control-label">
                                        备注</label>
                                    <div class="controls">
                                        <div class="textarea">
                                            <textarea type="" class=""> </textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <!-- Button -->
                                    <div class="controls">
                                        <button id="button_AddExzam" class="btn btn-success">
                                            提交</button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                    </setion>

            
                <setion id="finalEdit">
                <div class=" hero-unit ">
                 <div id="Div1" class="">
                        <legend class="">修改考试</legend>
                    </div>
                    <div class="control-group ">
                    <!-- Select Basic -->
                    <form class=" form-inline">
                    <label class="control-label">选择课程:</label>
                        <select id="select-course2" class=" input-medium"></select>
                    </form>
                 </div>
                <table id="exzamtable" class="table table-hover">
				</table>
                <button type="submit" class="btn btn-success">保存</button>
                <button type="" class="btn  btn-success">清空</button>
                </div>
                </setion>
            </div>
            <!--/row-->
        </div>
        <!--/span-->

    </div>
    <!--/row-->
    <hr>
    <footer>
        <p>&copy; Company 2013</p>
    </footer>
    </div><!--/.fluid-container-->
    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="./js/jquery.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <script src="js/mainMenu.js" type="text/javascript"></script>
    <script src="js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <script src="js/messenger.js" type="text/javascript"></script>
    <link href="css/messenger.css" rel="stylesheet" type="text/css" />
    <link href="css/messenger-theme-future.css" rel="stylesheet" type="text/css" />

    <script>
        //根据课程和老师id显示考试信息表
        function showExamByTechCourse() {
            var techid = "1";
            var courseid = $("#select-course2").val();
            var column = ['name', 'place', 'starttime', 'endtime', 'typename', 'exzamweight']
            $.post("./handler/ExzamHandler.ashx",
                  { 'action': 'getExzamByCourseTech', 'courseid': courseid, 'techid': techid },
                         function (data, status) {
                             getFullTableRows2("exzamtable", data, column, 'exzamid');
                             $("#exzamtable td").click(switchToClick);
                         }, 'json');
        }
    </script>

    <script>
        //获取条件选项
        var term = "2013下";
        var techid = "1";
        getConditByParams(
            {
                'action': 'getCourseByTechTerm',
                'term': term,
                'techid': techid
            },
            {
                selectid: "select-course",
                idcolum: "actualceid",
                name: "coursename"
            },
              function () { }
              );
        getConditByParams(
            {
                'action': 'getExzamtype'
            },
            {
                selectid: "select-exzamtype",
                idcolum: "typeid",
                name: "typename"
            },
              function () { }
              );
        getConditByParams(
            {
                'action': 'getCourseByTechTerm',
                'term': term,
                'techid': techid
            },
            {
                selectid: "select-course2",
                idcolum: "actualceid",
                name: "coursename"
            },
              function () {
                  $('#select-course2').change(showExamByTechCourse);
                  $('#select-course2').change();
              }
              );
        //添加考试
        $("#button_AddExzam").click(function () {
            var courseid = $("#select-course").val();
            var exzamname = $("#exzamname").val();
            var starttime = $("#starttime").val();
            var endtime = $("#endtime").val();
            var exzamplace = $("#exzamplace").val();
            var exzamtype = $("#select-exzamtype").val();
            var param = {
                'action': 'addExzam',
                'courseid': courseid,
                'exzamname': exzamname,
                'starttime': starttime,
                'endtime': endtime,
                'exzamplace': exzamplace,
                'exzamtype': exzamtype
            };
            $.post("./handler/ExzamHandler.ashx", param, function () {
                $.globalMessenger().post("添加成功");
                showExamByTechCourse();
            });
        });
    </script>

    <script>
        function getSelectValByText(selectid, text) {
            var select = $("#" + selectid);
            var val;
            $(select.children()).each(function (i, item) {
                if (text == $(item).text()) {
                    val = $(item).val();
                }
            });
            return val
        }
    </script>
    <script>
        //根据老师id显示添加的考试
        var courseid = $("#select-course2").val();
        var techid = "1";

        //表格的修改
        function switchToClick() {

            var select = $('#select-exzamtype').clone();
            var c = $(this).text();
            var selecttid;
            selecttid = getSelectValByText("select-exzamtype", c);
            if ($(this).text() == $(this).parent().children().eq(4).text()) {
                $(this).html(select.val(selecttid).attr("id", ""));
                $(this).find("select").focus();//////////
                //$(this).unbind();
                $(this).find("select").blur(switchToBlur2);
            }
            else if ($(this).text() == $(this).parent().children().eq(2).text()
                || $(this).text() == $(this).parent().children().eq(3).text()
                ) {
                var input = "<input class='mydate'  type='text' value='" + c + "' />";

                $(this).html(input);
                $('.mydate').datetimepicker({
                    format: 'yyyy-mm-dd hh:ii',
                    todayBtn: true,
                }).on('changeDate', function (ev) {
                    switchToBlurDate($('#exzamtable').find("input"));
                });
                $(this).find("input").focus();
            }
            else {
                $(this).html("<input  type='text' value='" + c + "' />");
                $(this).find("input").focus();
                $(this).find("input").blur(switchToBlur);
            }
        }
        function switchToBlurDate(date) {
            var c = $(date).val();
            console.log(c);
            console.log(date);
            var td = $(date).parent();
            td.html(c);
            editPost(td);

        }
        function switchToBlur() {
            var c = $(this).val();
            var td = $(this).parent();
            td.html(c);
            editPost(td);

        }
        function switchToBlur2() {
            var c = $("#select-exzamtype").find("[value='" + $(this).val() + "']").text()
            var td = $(this).parent();
            td.attr("value", $(this).val());
            td.html(c);
            editPost(td);
            $(this).bind("click");
        }


    </script>
    <script>
        //考试修改
        function editPost(td) {
            var tr = $(td).parent();
            var exzamid = tr.attr("exzamid");
            var name = tr.children().eq(0).text();
            var place = tr.children().eq(1).text();
            var starttime = tr.children().eq(2).text();
            var endtime = tr.children().eq(3).text();
            var typeid = getSelectValByText("select-exzamtype", tr.children().eq(4).text());
            var exzamweight = tr.children().eq(5).text();
            var params = {
                'action': 'singleExzamEdit',
                'exzamid': exzamid,
                'name': name,
                'place': place,
                'starttime': starttime,
                'endtime': endtime,
                'typeid': typeid,
                'exzamweight': exzamweight
            };
            console.log(params);
            $.post("./handler/ExzamHandler.ashx", params, function (data, status) {
                $.globalMessenger().post("更新成功");
            });
        }


    </script>
    <script>
        //日期拾取器

        $('#starttime').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
        $('#endtime').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    </script>
  

</body>
</html>
